﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Timers;
using System.Web;

namespace TSharp.Core.AppBox.Handlers
{
    public class ConfigPerfmonHtttpHandler : BaseHttpHandler
    {
        const string HtmlFormat = @"
<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml"">
<head>
    <title>性能监视</title>
    <script type=""text/javascript"" src=""{0}/Scripts/jquery-1.4.2.js""></script>
</head>
<body>
<input type=""button"" value=""start"" onclick=""toggle(this)"" />
    <br />
    <img src=""{0}/tjb/{1}"" id=""MyImg"" alt=""流浪的小图片"" />
    <script type=""text/javascript"">
        $(function () {{
            
        }});
        function toggle(obj) {{
            if (obj.value == 'start') {{
                start();
                obj.value = ""stop"";
            }} else {{
                stop();
                obj.value = ""start"";
            }}
        }}
        var intervalHandle;
        function start() {{
            if (!intervalHandle)
                intervalHandle = setInterval(function () {{
                    $(""#MyImg"").attr(""src"", ""{0}/tjb/{1}?"" + new Date().getTime());
                }}, 1000);
        }}
        function stop() {{
            if(intervalHandle)
                clearInterval(intervalHandle);
            intervalHandle =null;
        }}
    </script>
</body>
</html>
";
        


        public ConfigPerfmonHtttpHandler(HttpContext context, string requestType, string url, string pathTranslated)
            : base(context, requestType, url, pathTranslated)
        { }


        public override void ProcessRequest(HttpContext context)
        {
            //  var stp = context.Session[""""] as SmartThreadPool;
            var p = context.Request.ApplicationPath;
            context.Response.Write(string.Format(HtmlFormat, p == "/" ? "" : p, "PerfmonImageHandler.axd"));
        }
    }
}